// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import then from 'thenjs';
import Vue from 'vue';
import iView from 'iview';
import VueRouter from 'vue-router';
import Routers from './routers';
import Vuex from 'vuex';
import App from './app.vue';
import UserModule from "./libs/user-module";
import UserInfo from "./libs/user-info";




import 'iview/dist/styles/iview.css';
import AppFrame from './libs/app-frame';

Vue.config.productionTip = false
Vue.use(VueRouter);
Vue.use(Vuex);
Vue.use(iView);

//console.log(Routers);
//alert(process.env.NODE_ENV);
const MsgBus = new Vue();
// 路由配置
const RouterConfig = {
    mode: 'history',
    routes: Routers
};
const router = new VueRouter(RouterConfig);
router.beforeEach((to, from, next) => {
    // console.log(to); 
    let url = location.pathname;
    let uifo = UserInfo.getUserInfo();

    if (url.toLocaleLowerCase().indexOf('/manage/login') < 0 && !uifo) {
        let partnersSign = localStorage.getItem('partnerSign')?localStorage.getItem('partnerSign'):'system';
        location.href = "/manage/login/"+partnersSign;
    } else {

        iView.LoadingBar.start();
        store.state.isPageLoading = true;
        window.document.title = to.meta.title;
        store.state.MsgBus.$emit('UrlAfter', to.path);
        next();
    }




});

router.afterEach(() => {

    setTimeout(() => {
        iView.LoadingBar.finish();
        window.scrollTo(0, 0);
        store.state.isPageLoading = false;
    }, 100);

});

var CurUserInfo = AppFrame.UserInfo.getUserInfo();
if (CurUserInfo && CurUserInfo.UserID > 0) {
    AppFrame.Socket.CreateWebSocket(CurUserInfo.UserID);
    // setTimeout(function () {
    //     let Client = AppFrame.Socket.getClient();
    //     console.log(Client)
    //     Client.emit('SendMsgToRoom',{Msg:1,b:2})
    // },3000)
}

const store = new Vuex.Store({
    state: {
        socketClient: AppFrame.Socket.getClient(),
        MsgBus: MsgBus,
        isPageLoading: true,
        //CurModuleID:0, //当前访问的模块ID
        pageContentBackGroudColor: "#fff", //主页面背景色
        PageMainContentPadding:"10px"
    },
    getters: {

    },
    mutations: {

    },
    actions: {

    }
});



new Vue({
    el: '#app',
    router,
    store: store,
    render: h => h(App)
})